package com.jxchexie.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jxchexie.signin.R;

import java.util.ArrayList;

public class MainPicAdapter extends RecyclerView.Adapter<MainPicAdapter.ListViewHolder> {
    //图片数组

    private ArrayList<Integer> mdatas;

    private Context mContext;

    public MainPicAdapter(ArrayList<Integer> datas, Context context) {
        mdatas = datas;
        mContext = context;
    }

    @Override
    public ListViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        MainPicAdapter.ListViewHolder holder = new MainPicAdapter.ListViewHolder(LayoutInflater.from(mContext)
                .inflate(R.layout.item_main_pic, viewGroup, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(ListViewHolder listViewHolder, int i) {
        listViewHolder.img.setImageResource(mdatas.get(i));
    }

    @Override
    public int getItemCount() {
        if(mdatas==null || mdatas.size()<=0){
            return 0;
        }
        return mdatas.size();
    }

    static class ListViewHolder extends RecyclerView.ViewHolder {

        com.makeramen.roundedimageview.RoundedImageView img;

        public ListViewHolder(View itemView) {
            super(itemView);
            img = (com.makeramen.roundedimageview.RoundedImageView) itemView.findViewById(R.id.mPic);
        }
    }
}
